<form action="{:sysuri()}" method="post" data-auto="true" class="layui-form layui-card" data-table-id="CarsTable">
    <div class="layui-card-body">
        <div class="layui-form-item">
            <label class="layui-form-label">标题：</label>
            <div class="layui-input-block">
                <input type="text" name="title" placeholder="请输入标题" value="{$vo.title|default=''}" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">版本类型：</label>
            <div class="layui-input-block">
                <input type="text" name="version_type" placeholder="请输入版本类型" value="{$vo.version_type|default=''}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">Logo：</label>
            <div class="layui-input-block">
                <input type="hidden"  name="logo" value="{$vo.logo|default=''}">
                <script>$('[name=logo]').uploadOneImage();</script>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">背景图片：</label>
            <div class="layui-input-block">
                <input type="hidden"  name="bg_img" value="{$vo.bg_img|default=''}">
                <script>$('[name=bg_img]').uploadOneImage();</script>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">背景图片1：</label>
            <div class="layui-input-block">
                <input type="hidden"  name="bg_img1" value="{$vo.bg_img|default=''}">
                <script>$('[name=bg_img1]').uploadOneVideo();</script>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">规格：</label>
            <div class="layui-input-block">
                <input type="text" name="specification" placeholder="请输入规格" value="{$vo.specification|default=''}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">蓝豆：</label>
            <div class="layui-input-block">
                <input type="number" name="beans" placeholder="请输入蓝豆数量" value="{$vo.beans|default=''}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">时长(月)：</label>
            <div class="layui-input-block">
                <input type="number" name="duration" placeholder="请输入有效期" value="{$vo.duration|default=''}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">价格(元)：</label>
            <div class="layui-input-block">
                <input type="number" name="price" placeholder="请输入价格" value="{$vo.price|default=''}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">划线价格(元)：</label>
            <div class="layui-input-block">
                <input type="number" name="hx_price" placeholder="请输入划线价格" value="{$vo.hx_price|default=''}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设备数量：</label>
            <div class="layui-input-block">
                <input type="number" name="devices" placeholder="请输入设备数量" value="{$vo.devices|default=''}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">音频数量：</label>
            <div class="layui-input-block">
                <input type="number" name="voices" placeholder="音频数量" value="{$vo.voices|default=''}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">视频数量：</label>
            <div class="layui-input-block">
                <input type="number" name="videos" placeholder="视频数量" value="{$vo.videos|default=''}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">套餐权益：</label>
            <div class="layui-input-block">
                {foreach $benefits as $benefit}
                <label class="think-checkbox">
                    {if in_array($benefit.id, $vo.benefits)}
                    <input type="checkbox" checked name="benefits[]" value="{$benefit.id}" lay-ignore>{$benefit.content}
                    {else}
                    <input type="checkbox" name="benefits[]" value="{$benefit.id}" lay-ignore>{$benefit.content}
                    {/if}
                </label>
                {/foreach}
            </div>
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label">描述：</label>
            <div class="layui-input-block">
                <textarea placeholder="" class="layui-textarea"   name="additional_info">{$vo.additional_info|default=""}</textarea>
            </div>
        </div>



    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type="submit">{:lang('保存数据')}</button>
        <button class="layui-btn layui-btn-danger" type="button" data-confirm="{:lang('确定要取消编辑吗？')}" data-close>{:lang('取消编辑')}</button>
    </div>
</form>

<script>
    require(['angular', 'ckeditor'], function () {

        let editor;
        editor = window.createEditor('[name="content"]');
    })
    let i = "{$vo.attachment_num|default='0'}";
    $(function () {

        /*！文件上传过程及事件处理 */
        $('#attachment').on('upload.choose', function (files) {
            // 文件选择后的事件
        }).on('upload.hash', function (event, file) {
            // file 当前文件对象
        }).on('upload.progress', function (event, obj) {
            // obj.file 当前文件对象
            // obj.event 文件上传进度事件
            // obj.number 当前上传进度值
        }).on('upload.done', function (event, obj) {
            // obj.file 当前完成的文件对象，每个文件上传成功将会调用
            // obj.data 当前文件上传后服务端返回的内容，部分云上传不会返回数据
            console.log(obj)
            let data = obj.data;
            let file = obj.file;
            if(data.code == 1){
                let html = '<div class="file-item">\n' +
                    '                        <a href="'+data.data.url+'" target="_blank" style="margin-right: 5px" >'+file.name+'</a>\n' +
                    '                        <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger" onclick="removeFile(this)" ><i class="layui-icon">&#xe693;</i></a>\n' +
                    '                        <input type="hidden" name="attachment['+i+'][name]" value="'+file.name+'">\n' +
                    '                        <input type="hidden" name="attachment['+i+'][url]" value="'+data.data.url+'">\n' +
                    '                    </div>';
                $('.layui-upload-list').append(html);
                i++;
            }
        }).on('upload.complete', function (event) {
            // 全部文件上传成功
        });
    });
    function removeFile(obj) {
        $(obj).parent().remove();
    }
</script>

